package com.etc.zmall.service.impl;

import java.util.List;

import com.etc.dao.UserDao;
import com.etc.dao.impl.UserDaoImpl;
import com.etc.entity.User;
import com.etc.util.MD5Util;
import com.etc.util.PageData;
import com.etc.zmall.service.UserService;

/**
 * 
 * <p>
 * Title: UserServiceImpl
 * </p>
 * 
 * <p>
 * Description:
 * </p>
 * 
 * @author knowno
 * 
 * @date 2021年1月11日
 * 
 */
public class UserServiceImpl implements UserService {

	UserDao ud = new UserDaoImpl();

	@Override
	public User login(String username, String pwd) {
		// 将密码转换为密文
		String userpwd = MD5Util.getEncodeByMd5(pwd);
		User user = ud.userLogin(username, userpwd);
		return user;
	}

	@Override
	public User getUsersByName(String username) {
		// TODO Auto-generated method stub
		return ud.getUserByName(username);
	}

	public PageData<User> getUserByPage(int pageNo, int pageSize, String keywords, String usersex) {
		return ud.getUserByPage(pageNo, pageSize, keywords, usersex);
	}

	public boolean update(User user) {
		return ud.modUser(user.getUserid(), user.getUsername(), user.getUserpwd(), user.getUserphone(),
				user.getAddress());
	}

	@Override
	public boolean updateUser(int userid, int userstate) {
		// 判断，先将用户状态信息查询出来， ->0 userstate->0

		User user = ud.getUserById(userid);

		if (user == null) {
			return false;
		}
		if (user != null) {
			if (user.getUserstate() == userstate) {
				return false;
			}
		}
		return ud.updateUser(userid, userstate);
	}

}
